home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Copy Folder < prev    next >
Encoding:
Text File  |  1999-03-04  |  4.3 KB  |  183 lines  |  [TEXT/ToyS]

  1. -- Properties
  2. property kasName : "Copy Folder V1.0"
  3. property kasSrc : path to system folder as alias -- "Source:topfolder:"
  4. property kasDst : ""
  5.  
  6. -- Globals
  7. global gasFoldersToDo -- The folders left to process
  8. global gasDestFold -- Current destination
  9. global gasDestTop -- kasDst & name of kasSrc
  10. global gwdInfo -- Info window
  11.  
  12.  
  13. on run
  14.     set kasDst to ":" as alias
  15.     open {kasSrc} -- Default to kasSrc
  16. end run
  17.  
  18.  
  19. on open fsObjs
  20.     InfoNew()
  21.     
  22.     -- Start up stuff
  23.     set gasFoldersToDo to {}
  24.     -- Our destination folder named as the source folder
  25.     set srcName to ":" & (original name of (alias info from kasSrc)) & ":"
  26.     set gasDestTop to verify path srcName relative to kasDst
  27.     set gasDestFold to gasDestTop -- Single items to this folder
  28.     
  29.     -- Separate files from folders
  30.     repeat with fsObj in fsObjs
  31.         set myInfo to (basic info for fsObj)
  32.         
  33.         if (catalog kind of myInfo is a folder) then
  34.             PushFolder(fsObj)
  35.         else
  36.             if not DoOne(fsObj) then ShowErrorItem(catalog name of myInfo)
  37.         end if
  38.     end repeat
  39.     
  40.     -- Do folders
  41.     repeat while gasFoldersToDo is not {}
  42.         GoDeep(PopFolder())
  43.     end repeat
  44.     
  45.     InfoDel()
  46. end open
  47.  
  48.  
  49. on DoOne(fsObj)
  50.     -- display dialog "Src:" & fsObj & return & "Dst:" & gasDestFold
  51.     try
  52.         AkuaCopy fsObj to gasDestFold with overwriting
  53.         return true
  54.     on error errStr number errNum
  55.         ShowError(errStr, errNum)
  56.         return false
  57.     end try
  58. end DoOne
  59.  
  60.  
  61. on GoDeep(foldObj)
  62.     set daddy to foldObj as string
  63.     ShowPath(daddy)
  64.     
  65.     -- Create our subfolder in destination
  66.     set srcPath to kasSrc as string
  67.     -- Subtract that from front of daddy
  68.     set subPath to the text from character (length of srcPath) to -1 of daddy
  69.     -- Create the path in the destination
  70.     set gasDestFold to verify path subPath relative to gasDestTop
  71.     
  72.     -- Queue folders
  73.     set myItems to the entries in foldObj ¬
  74.         whose kinds are a folder
  75.     repeat with myItem in myItems
  76.         PushFolder((daddy & myItem) as alias)
  77.     end repeat
  78.     
  79.     -- Do files
  80.     set myItems to the entries in foldObj ¬
  81.         whose kinds are a file
  82.     -- If you don't want to copy aliases, comment out the following line
  83.     set myItems to myItems & (the entries in foldObj ¬
  84.         whose kinds are an alias)
  85.     
  86.     set n to (the number of items in myItems)
  87.     
  88.     if (n > 0) then
  89.         if (n > 10) then
  90.             -- Progress window for folders w/ more than 10 items
  91.             set itemPg to display progress titled ("Folder Copy") ¬
  92.                 subtitled (catalog name of (basic info for foldObj)) ¬
  93.                 maximum n
  94.         else
  95.             set itemPg to 0
  96.         end if
  97.         
  98.         repeat with myItem in myItems
  99.             if (itemPg is not 0) then ¬
  100.                 if canceled of (display progress itemPg labeled myItem value 0) then ¬
  101.                     display dialog "Continue with the rest?"
  102.             ShowItem(myItem)
  103.             if not DoOne((daddy & myItem) as string) then ShowErrItem(myItem)
  104.         end repeat
  105.         
  106.         if (itemPg is not 0) then ¬
  107.             display progress itemPg with disposal
  108.     end if
  109. end GoDeep
  110.  
  111.  
  112. on PushFolder(foldAli)
  113.     set gasFoldersToDo to gasFoldersToDo & {foldAli}
  114.     ShowFolderCnt(number of items of gasFoldersToDo)
  115. end PushFolder
  116.  
  117.  
  118. on PopFolder()
  119.     -- Pop one off the front
  120.     copy item 1 of gasFoldersToDo to fsObj
  121.     set gasFoldersToDo to edit list gasFoldersToDo with edits {-1}
  122.     ShowFolderCnt(number of items of gasFoldersToDo)
  123.     return fsObj
  124. end PopFolder
  125.  
  126.  
  127. on ShowPath(fsPath)
  128.     display info gwdInfo ¬
  129.         message ("Path: " & fsPath)
  130. end ShowPath
  131.  
  132.  
  133. on ShowItem(fsName)
  134.     display info gwdInfo ¬
  135.         message ("File: " & fsName) at line 2
  136. end ShowItem
  137.  
  138.  
  139. on ShowError(errStr, errNum)
  140.     display info gwdInfo ¬
  141.         message ("Error: " & errStr & " (" & errNum & ")") at line 3 ¬
  142.         using bg color (30 * 1024) + (25 * 32) + 25
  143.     -- User canceled?
  144.     if (errNum is -128) then display dialog ("Continue?")
  145. end ShowError
  146.  
  147.  
  148. on ShowErrItem(fsName)
  149.     display info gwdInfo ¬
  150.         message ("…copying " & fsName) at line 4 ¬
  151.         using bg color (30 * 1024) + (25 * 32) + 25
  152.     beep
  153.     pause for 120
  154.     if (option key down of (input state)) then display dialog ("Continue?")
  155. end ShowErrItem
  156.  
  157.  
  158. on ShowFolderCnt(n)
  159.     display info gwdInfo ¬
  160.         message ("Folders to go: " & n) at line 5
  161. end ShowFolderCnt
  162.  
  163.  
  164. on InfoNew()
  165.     try
  166.         set pref to load preference named kasName
  167.     on error
  168.         set pref to {pfWLoc:{60, 80}}
  169.     end try
  170.     
  171.     set gwdInfo to display info titled kasName ¬
  172.         located at (pfWLoc of pref) ¬
  173.         message ("To: " & kasDst) ¬
  174.         at line 10
  175. end InfoNew
  176.  
  177.  
  178. on InfoDel()
  179.     set wLoc to screen location of ¬
  180.         (display info gwdInfo with disposal)
  181.     save preference {pfWLoc:wLoc} named kasName
  182. end InfoDel
  183.